package com.changgou.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.RequestPath;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

/**
 * 获取用户访问的url过滤器
 */
@Component
public class URLFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("第二个过滤器执行了");
        URI uri = exchange.getRequest().getURI();
        System.out.println("uri = " + uri);
        String path = uri.getPath();
        System.out.println("path = " + path);
        return chain.filter(exchange);
    }

    /**
     * 设置过滤器执行的优先级
     * @return 返回的int数值越小，越优先执行
     */
    @Override
    public int getOrder() {
        return 2;
    }
}
